package EXtension.FrameWork;

import java.util.*;

public class EventSystem {

    public static EventSystem instance=new EventSystem();
    TreeMap<String,EasyDelegate> m=new TreeMap<>();



    public void register(MyDelegate myDelegate){
        if(!m.containsKey(myDelegate.eventName)){
            m.put(myDelegate.eventName,new EasyDelegate(myDelegate.eventName));
        }
        m.get(myDelegate.eventName).toDoList.add(myDelegate);
        System.out.println("RG"+myDelegate.eventName);
    }
    public void unRegister(MyDelegate myDelegate){
        if(m.containsKey(myDelegate.eventName)){
            m.remove(myDelegate.eventName);
        }
    }
    public void SendEvent(String eventName,Object data){
        if(m.containsKey(eventName)){
            m.get(eventName).execute(data);
            System.out.println("SE"+eventName);
        }
    }
}
